Page({
  data: {
    activeTab: 'game',
    selectedDictionary: '',
    courseList: {
      course: ['三年级上册', '三年级下册', '四年级上册', '四年级下册'],
      cambridge: ['预备级', '一级', '二级', '三级']
    },
    studyProgress: {
      wordGame: 65,
      wordRead: 45,
      wordListen: 30,
      wordWrite: 20
    },
    stats: {
      todayWords: 50,
      totalWords: 1280,
      studyDays: 16
    }
  },

  // 显示词库选择
  showDictionarySelect(type) {
    wx.showActionSheet({
      itemList: ['课程词库', '剑桥词库'],
      success: (res) => {
        const dictionary = res.tapIndex === 0 ? 'course' : 'cambridge';
        if (type) {
          this.navigateToModule(type, dictionary);
        } else {
          this.setData({
            activeTab: 'schedule',
            selectedDictionary: dictionary
          });
        }
      }
    });
  },

  switchTab(e) {
    const tab = e.currentTarget.dataset.tab;
    if (tab === 'schedule') {
      this.showDictionarySelect();
    } else {
      this.setData({
        activeTab: tab,
        selectedDictionary: ''
      });
    }
  },

  // 跳转到录播课列表
  navigateToCourseList(e) {
    const { dictionary, level } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/subpkg/pages/course-list/course-list?dictionary=${dictionary}&level=${level}`
    });
  },

  // 根据选择的词库跳转到对应页面
  navigateToModule(type, dictionary) {
    const routes = {
      challenge: '/subpkg/pages/word-challenge/word-challenge',
      reading: '/subpkg/pages/word-reading/word-reading',
      dictation: '/subpkg/pages/word-dictation/word-dictation',
      sentence: '/subpkg/pages/sentence-practice/sentence-practice'
    };

    wx.navigateTo({
      url: `${routes[type]}?dictionary=${dictionary}`
    });
  },

  goToWordChallenge() {
    wx.navigateTo({
      url: '/subpkg/pages/word-challenge/word-challenge'
    });
  },

  goToWordReading() {
    wx.navigateTo({
      url: '/subpkg/pages/word-reading/word-reading'
    });
  },

  goToWordDictation() {
    wx.navigateTo({
      url: '/subpkg/pages/word-dictation/word-dictation'
    });
  },

  goToSentencePractice() {
    wx.navigateTo({
      url: '/subpkg/pages/sentence-practice/sentence-practice'
    });
  },

  goToWordListening() {
    wx.navigateTo({
      url: '/subpkg/pages/word-listening/word-listening'
    });
  }
});